/*
 * ============================================================================
 *                   GNU Lesser General Public License
 * ============================================================================
 *
 *
 *
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 * 
 *
 *
 */
package rad.framework.jaxrpc;

import javax.xml.namespace.QName;
import javax.xml.rpc.handler.GenericHandler;
import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.soap.SOAPMessageContext;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author boudyacho
 * @deprecated
 */
public abstract class BaseHandler extends GenericHandler {
	protected static final Log logger = LogFactory.getLog(BaseHandler.class);

	private QName[] headers = new QName[] {};

	public QName[] getHeaders() {
		return headers;
	}

	private HandlerInfo config;

	public void init(HandlerInfo config) {
		this.config = config;
	}

	protected String getInitParam(String name) {
		return (String) config.getHandlerConfig().get(name);
	}

	protected boolean hasInitParam(String name) {
		return config.getHandlerConfig().containsKey(name);
	}

	protected void log(Object o) {
		if (logger.isDebugEnabled()) {
			logger.debug(ToStringBuilder.reflectionToString(o,
					ToStringStyle.MULTI_LINE_STYLE));
		}
	}

	protected void log(String prefix, MessageContext msgContext) {
		if (logger.isDebugEnabled()) {
			logger.debug(prefix);
			logger.debug(ToStringBuilder.reflectionToString(msgContext,
					ToStringStyle.MULTI_LINE_STYLE));
			logger.debug(ToStringBuilder.reflectionToString(
					((SOAPMessageContext) msgContext).getMessage(),
					ToStringStyle.MULTI_LINE_STYLE));
		}
	}
}
